<template>
  <div class="box">
    <div class="c-box">
      <div class="l-box">
        <div class="l-tit">{{ artInfo?.title }}</div>
        <div
          class="l-content"
          v-if="artInfo.content"
          v-html="videoPlace > 0 ? artInfo.content.substring(0, videoPlace) : artInfo.content"
        ></div>
        <div class="more-btn" @click="goAbout">{{ btn.rm }}</div>
      </div>
      <div class="r-box">
        <img class="p-ico" v-if="!videoShow" src="/image/about/play.png" alt="" @click="openVideo" />
        <img class="r-img" v-if="!videoShow" :src="artInfo.picUrl" alt="" />
        <video v-if="videoShow" class="r-video" :src="videoInfo" controls autoplay></video>
      </div>
    </div>
    <div class="bg"></div>
  </div>
</template>
<script lang="ts" setup>
import { language } from "~/conf";
const router = useRouter();
const { btn } = language;
const props = defineProps<{
  article1: number;
}>();
type TartInfo = {
  content: string;
  picUrl: string;
  title: string;
};
let artInfo = ref<TartInfo>({
  content: "",
  picUrl: "",
  title: "",
});
let videoShow = ref(false);
let hvVideo = ref(false);
let videoInfo = ref("");
let videoPlace = ref(-1);

const openVideo = () => {
  videoShow.value = true;
};
const getInfo = async () => {
  const { data } = (await useServerFetch<TartInfo>("/app-api/promotion/article/get", {
    query: {
      id: props.article1,
    },
  })) as { data: TartInfo };
  artInfo.value = data;
  if (data.content.indexOf("==video") > 0) {
    //have video
    hvVideo.value = true;
    const index = data.content.indexOf('==video:"<a href="');
    const urlA = data.content.substring(index);
    const formIndex = urlA.indexOf("https");
    const endIndex = urlA.indexOf('" target');
    videoInfo.value = urlA.substring(formIndex, endIndex);
    videoPlace.value = index;
  }
};
const goAbout = () => {
  router.push({ name: "about" });
};
onMounted(() => {
  getInfo();
});
</script>
<style lang="stylus" scoped>
.box{
  position relative
  width:1080px;
  box-sizing border-box
  margin 0 auto
  .c-box{
    position relative
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index 2
    .l-box{
      position relative
      padding-left 34px
      .l-tit{
        font-weight: bold;
        font-size: 30px;
        color: #F6F3F3;
        margin-bottom 30px
      }
      .l-content{
        width: 399px;
        font-weight: 300;
        font-size: 13px;
        color: #F6F3F3;
        line-height: 21px;
        margin-bottom 32px
      }
      .more-btn{
        width: 142px;
        height: 32px;
        background: #000000;
        border-radius: 15px;
        font-weight: 400;
        font-size: 14px;
        color: #FFFFFF;
        line-height 32px
        text-align center
        cursor pointer
      }
    }
    .r-box{
      position relative
      width 625px;
      height: 420px;
      overflow hidden
      text-align center
      align-items center
      .r-img{
        position relative
        width 100%;
        display block
      }
      .r-video{
        position relative
        width 625px;
        height: 420px;
        z-index 2
        display block;
      }
      .p-ico{
        position absolute
        left 50%;
        top 50%;
        transform translate(-50%,-50%)
        width 50px
        cursor pointer
        opacity .4
        z-index 9
      }
    }
  }

  .bg{
    position absolute
    bottom 0
    left 0
    width 100%
    height: 420px;
    background: #C0AB82;
  }
}
</style>
